Back

Contents

Add a metallb load balancer to a bare metal k8s cluster.md

Install

  1. Enable ARP (strictARP: true) on the cluster.

     kubectl edit configmap -n kube-system kube-proxy
  2. Apply manifests (for namespace and metallb).

     kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
     kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml
  3. Create secret (first install only).

     kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
  4. Edit the config, adding the address pool that will be available to the load balancer. This can be either internal or externap IPs.

     $ vim metal_config.yaml
     apiVersion: v1
     kind: ConfigMap
     metadata:
       namespace: metallb-system
       name: config
     data:
       config: |
         address-pools:
         - name: default
           protocol: layer2
           addresses:
           - <ip_range_low>-<ip_range_high>

    Note that if want to serve a single internal load balancer accessible from the VM's IP (e.g. via a reverse proxy), the range here should be set to the IP of the VM.

  5. Apply this config.

     kubectl apply -f metal_config.yaml

Resetting the load balancer

To force a reset, delete all pods in metallb-system namespace:

kubectl delete po -n metallb-system --all

Top